
package net.swa.dewei.web.action;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Required;
import net.swa.dewei.beans.entity.ChongdianZhan;
import net.swa.dewei.service.ChongdianZhanService;
import net.swa.system.beans.entity.User;
import net.swa.system.service.ICommonService;
import net.swa.system.util.SysConst;
import net.swa.system.util.annotation.Log;
import net.swa.system.web.action.AbstractBaseAction;
import net.swa.util.DateUtils;
import net.swa.util.JsonResult;

/** 门店信息表 Action **/
public class ChongdianZhanAction extends AbstractBaseAction
{
    private static final long serialVersionUID = 1908627223355967719L;

    private static final Logger log = Logger.getLogger(ChongdianZhanAction.class);

    private ChongdianZhanService ChongdianZhanService;

    private ChongdianZhan model;

    // 实体类id
    private Long id;

    // 批量删除的id集合
    private Long[] ids;

    private String name;

    private String address;

    private String lxr;

    /** 公用方法接口 */
    private ICommonService commonService;

    /** 初始化分页查询 **/
    @Log(description = "初始化充电站分页查询")
    public String listPage()
    {
        return "listPage";
    }

    /**充电站分页查询**/
    public String queryChongdianZhanPage() throws Exception
    {
        currentPage = currentPage == 0 ? 1 : currentPage;
        pageSize = pageSize == 0 ? 20 : pageSize;
        JsonResult<ChongdianZhan> json = null;
        json = ChongdianZhanService.queryChongdianZhanPage(name, address, lxr, currentPage, pageSize, orderBy,
                orderType);
        json.setCurrentPage(currentPage);
        outJson(json);
        return null;
    }

    /** 去新增或者修改页面 **/
    @Log(description = "去新增或者修改充电站")
    public String toAddChongdianZhan() throws Exception
    {
        if (null != id)
        {
            model = commonService.commonFind(ChongdianZhan.class, id);
        }
        else
        {
            model = new ChongdianZhan();
        }
        return "toAddChongdianZhan";
    }

    /** 新增或者修改 **/
    @Log(description = "保存充电站，到数据库")
    public String saveChongdianZhan() throws Exception
    {
        JsonResult<String> json = new JsonResult<String>();
        boolean isadmin = false;
        User u = getCurrentUser();
        if (null != u)
        {
            if (SysConst.USER_TYPE_ADMIN == u.getUserType())
            {
                isadmin = true;
            }
        }
        if (null == model.getId())
        {
            model.setCrateDate(DateUtils.getCurrDate(null));
            json = ChongdianZhanService.add(model, isadmin);
        }
        else
        {
            model.setUpdateDate(DateUtils.getCurrDate(null));
            json = ChongdianZhanService.update(model, isadmin);
        }
        outJson(json);
        return null;
    }

    /** * 删除方法 **/
    @Log(description = "删除充电站")
    public String delete() throws Exception
    {
        if (log.isDebugEnabled())
        {
            log.debug("删除充电站");
        }
        ChongdianZhanService.delete(ids);
        outSuccess();
        return null;
    }

    /** 根据门店id 查充电站 */
    public String queryById() throws Exception
    {
        if (null != id)
        {
            model = commonService.commonFind(ChongdianZhan.class, id);
            if (null != model)
            {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("success", true);
                map.put("model", model);
                outJson(map);
            }
            else
            {
                outError("cant not find");
            }
        }
        else
        {
            outError("id is null");
        }
        return null;
    }

    public ICommonService getCommonService()
    {
        return commonService;
    }

    @Required
    @Resource
    public void setCommonService(ICommonService commonService)
    {
        this.commonService = commonService;
    }

    public Long getId()
    {

        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public Long[] getIds()
    {
        return ids;
    }

    public void setIds(Long[] ids)
    {
        this.ids = ids;
    }

    public ChongdianZhan getModel()
    {
        return model;
    }

    public void setModel(ChongdianZhan model)
    {
        this.model = model;
    }

    @Required
    @Resource
    public void setChongdianZhanService(ChongdianZhanService ChongdianZhanService)
    {
        this.ChongdianZhanService = ChongdianZhanService;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getAddress()
    {
        return address;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }

    public String getLxr()
    {
        return lxr;
    }

    public void setLxr(String lxr)
    {
        this.lxr = lxr;
    }

}
